package com.hbnu.tonghengchang;

import com.sun.istack.internal.NotNull;

public class demo01 {
    public static void main(String [] args) {

        @NotNull
        char[] str = {1,2,3,4,5,6,7,8};

        char c = 7;

        int index = ErFenSearch(str,c);

        if (index!=404) System.out.println("index = " + index);
        else System.out.println("error, cannot find the target!!" );

    }

    public static int ErFenSearch(char[] str,char c) {
        int min = 0;
        int max = str.length-1;
        int mid = max;
        while (min < max){
            if (str[mid]>c){
                max = mid;
            }
            else if (str[mid]<c){
                min=mid;
            }
            else return mid;
            mid = (min+max)/2;
        }
        return 404;
    }
}
